package com.my.chapter15;

import java.util.ArrayList;
import java.util.Random;

public class practice6 {
    private static void dump(RandomList<?> rl) {
        for(int i = 0; i < 11; i++)
            System.out.print(rl.select() + " ");
        System.out.println();
    }

    public static void main(String[] args) {
        RandomList<String> rs = new RandomList<String>();
        for(String s: ("The quick brown fox jumped over " +
                "the lazy brown dog").split(" "))
            rs.add(s);
        dump(rs);
        RandomList<Integer> ri = new RandomList<Integer>();
        for(int i=0;i<11;i++){
            ri.add(i);
        }
        dump(ri);
        RandomList<Character> rc = new RandomList<Character>();
        for(int i=0;i<11;i++){
            rc.add((char) ('a' + i));
        }
        dump(rc);
    }
}

class RandomList<T>{
    private ArrayList<T> storage = new ArrayList<>();
    private Random rand = new Random(47);
    public void add(T item){
        storage.add(item);
    }
    public T select(){
        return storage.get(rand.nextInt(storage.size()));
    }
}
